## Figure 6: Differential Demand for Graffiti Removal by City and Neighborhood Race

## install.packages(c("tidyverse"))
## library(tidyverse)

## SET WORKING DIRECTORY HERE
## setwd()

## Loading data
## load("dta.RData")

## Prepping
demand_common = dta %>%
  filter(!is.na(common_service)) %>%
  mutate(non_white = case_when(white_third %in% c("1") ~ 1,
                               TRUE ~ 0),
         white = case_when(white_third %in% c("3") ~ 1,
                           TRUE ~ 0),
         poor = case_when(inc_third %in% c("1") ~ 1,
                          TRUE ~ 0),
         rich = case_when(inc_third %in% c("3") ~ 1,
                          TRUE ~ 0),
         n = 1) %>%
  group_by(city, common_service) %>%
  summarise(pct_poor = (sum(poor))/(sum(n)),
            pct_rich = (sum(rich))/(sum(n)),
            pct_white = (sum(white))/(sum(n)),
            pct_non_white = (sum(non_white))/(sum(n))) %>%
  ungroup() %>%
  mutate(poor_demand = (pct_poor - pct_rich)*100,
         non_white_demand = (pct_non_white - pct_white)*100,
         poor_need = case_when(poor_demand > 0 ~ 1,
                               TRUE ~ 0),
         non_white_need = case_when(non_white_demand > 0 ~ 1,
                                    TRUE ~ 0))

## Figure 6
graffiti_common = demand_common %>%
  filter(common_service == "Graffiti") %>%
  ggplot(aes(x = factor(reorder(city, non_white_demand)), y = non_white_demand)) +
  geom_bar(stat = "identity", color="black", fill="gray") +
  labs(x = "City",
       y = "% Requests from Non-White \n - % Requests from White") +
  theme_classic() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"))
